<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        class User {

        }
        //propName剩余参数,形成一个数组
        function ConstructorProxy(Class, ...propNames) {
            return new Proxy(Class, {
                construct(target, argumentsList) {
                    //得到实例对象
                    const obj = Reflect.construct(target, argumentsList)
                    console.log(propNames);
                    propNames.forEach((prop, i) => {
                        obj[prop] = argumentsList[i]
                    })
                    return obj
                }
            })
        }
        //得到代理的构造函数
        const userProxy = ConstructorProxy(User, 'firstName', 'lastName', 'age')
        const proxyObj = new userProxy('king', 'sen', '18')

        class Monster { }
        const MonsterProxy = ConstructorProxy(Monster, "attack", "defence", "hp", "rate", "name")
        const m = new MonsterProxy(10, 20, 100, 30, "怪物")
        console.log(m);

    </script>
</body>

</html>